package LeetCode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class LC_491_IncreasingSubsequences {

    public static void main(String[] args) {

    }

    public class Solution {

        public List<List<Integer>> findSubsequences(int[] nums) {
            List<Integer> tmp = new ArrayList<>();
            Set<List<Integer>> ans = new HashSet<>();
            combination(nums, 0, ans, tmp);
            return (new ArrayList<>(ans));
        }

        private void combination(int[] nums, int start, Set<List<Integer>> ans, List<Integer> tmp) {
            for (int i = start; i < nums.length; ++i) {
                if (tmp.size() == 0 || nums[i] >= tmp.get(tmp.size() - 1)) {
                    tmp.add(nums[i]);
                    if (tmp.size() >= 2)
                        ans.add(new ArrayList<>(tmp));
                    combination(nums, i + 1, ans, tmp);
                    tmp.remove(tmp.size() - 1);
                }
            }
        }

    }
}